﻿
using RTW.DAL;
using RTW.OA.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace RTW.OA.Areas.Common.Servers
{
    public class CarUseServers
    {
	    private readonly IRepository<vehicle_usage> vehicle_usageRepository;

        public CarUseServers()
        {
            vehicle_usageRepository = new DapperRepository<vehicle_usage>();

        }

        public List<vehicle_usage> GetData()
        {
            var datas = vehicle_usageRepository.GetAllEnumerable();
            return datas.ToList();
        }

        public vehicle_usage GetModelById(string id)
        {
            return vehicle_usageRepository.GetById(id);
        }

		
        internal void Add(vehicle_usage model)
        {
            vehicle_usageRepository.Insert(model);
        }

        internal void Update(vehicle_usage model)
        {
            vehicle_usageRepository.Update(model);
        }

		internal void Del(string id)
        {
            vehicle_usageRepository.DeleteByIds(id);
        }

				      
        internal List<SelectListItem> GetV_ID()
        {
            List<SelectListItem> tables = new List<SelectListItem>();
            var dstable = vehicle_usageRepository.SqlWithParamsDynamic("select ATTACHMENT_ID Value,concat(ATTACHMENT_ID,'-----',ATTACHMENT_NAME) Text from [dbo].[vehicle_car] where ATTACHMENT_ID Is not null and ATTACHMENT_NAME Is not null");
            tables.Clear();

            foreach (var dr in dstable)
            {
                string Id = dr.Value.ToString();
                string Title = dr.Text.ToString().Trim();
                tables.Add(new SelectListItem { Value = Id, Text = Title });
            }

            return tables;
        }


                   
        //internal List<SelectListItem> GetVU_PROPOSER()
        //{
        //    List<SelectListItem> tables = new List<SelectListItem>();
        //    var dstable = vehicle_usageRepository.SqlWithParamsDynamic("select a.name Value,concat(a.name,'-----',convert(nvarchar(max),b.value)) Text from sys.tables  a inner join  sys.extended_properties b on a.object_id=b.major_id and b.minor_id=0");
        //    tables.Clear();

        //    foreach (var dr in dstable)
        //    {
        //        string Id = dr.Value.ToString();
        //        string Title = dr.Text.ToString().Trim();
        //        tables.Add(new SelectListItem { Value = Id, Text = Title });
        //    }

        //    return tables;
        //}


                   
        internal List<SelectListItem> GetVU_USER()
        {
            List<SelectListItem> tables = new List<SelectListItem>();
            var dstable = vehicle_usageRepository.SqlWithParamsDynamic("select CODE_NO Value,concat(CODE_NO,'-----',CODE_NAME) Text  from [dbo].[sys_code] where PARENT_NO=99");
            tables.Clear();

            foreach (var dr in dstable)
            {
                string Id = dr.Value.ToString();
                string Title = dr.Text.ToString().Trim();
                tables.Add(new SelectListItem { Value = Id, Text = Title });
            }

            return tables;
        }


                   
        internal List<SelectListItem> GetVU_DEPT()
        {
            List<SelectListItem> tables = new List<SelectListItem>();
            var dstable = vehicle_usageRepository.SqlWithParamsDynamic("select CODE_NO Value,concat(CODE_NO,'-----',CODE_NAME) Text  from [dbo].[sys_code] where PARENT_NO=68");
            tables.Clear();

            foreach (var dr in dstable)
            {
                string Id = dr.Value.ToString();
                string Title = dr.Text.ToString().Trim();
                tables.Add(new SelectListItem { Value = Id, Text = Title });
            }

            return tables;
        }


                   
        internal List<SelectListItem> GetVU_OPERATOR()
        {
            List<SelectListItem> tables = new List<SelectListItem>();
            var dstable = vehicle_usageRepository.SqlWithParamsDynamic("select OPERATOR_ID Value,concat(OPERATOR_ID,'-----',OPERATOR_NAME) Text from [dbo].[vehicle_operator]select OPERATOR_ID Value,concat(OPERATOR_ID,'-----',OPERATOR_NAME) Text from [dbo].[vehicle_operator] where OPERATOR_ID Is not null and OPERATOR_NAME Is not null");
            tables.Clear();

            foreach (var dr in dstable)
            {
                string Id = dr.Value.ToString();
                string Title = dr.Text.ToString().Trim();
                tables.Add(new SelectListItem { Value = Id, Text = Title });
            }

            return tables;
        }


                   
        //internal List<SelectListItem> GetVU_DRIVER()
        //{
        //    List<SelectListItem> tables = new List<SelectListItem>();
        //    var dstable = vehicle_usageRepository.SqlWithParamsDynamic("select CODE_NO Value,concat(CODE_NO,'-----',CODE_NAME) Text  from [dbo].[sys_code] where PARENT_NO=");
        //    tables.Clear();

        //    foreach (var dr in dstable)
        //    {
        //        string Id = dr.Value.ToString();
        //        string Title = dr.Text.ToString().Trim();
        //        tables.Add(new SelectListItem { Value = Id, Text = Title });
        //    }

        //    return tables;
        //}


                   
        internal List<SelectListItem> GetSMS2_REMIND()
        {
            List<SelectListItem> tables = new List<SelectListItem>();
            var dstable = vehicle_usageRepository.SqlWithParamsDynamic("select CODE_NO Value,concat(CODE_NO,'-----',CODE_NAME) Text  from [dbo].[sys_code] where PARENT_NO=75");
            tables.Clear();

            foreach (var dr in dstable)
            {
                string Id = dr.Value.ToString();
                string Title = dr.Text.ToString().Trim();
                tables.Add(new SelectListItem { Value = Id, Text = Title });
            }

            return tables;
        }


                   
        internal List<SelectListItem> GetDEPT_MANAGER()
        {
            List<SelectListItem> tables = new List<SelectListItem>();
            var dstable = vehicle_usageRepository.SqlWithParamsDynamic("select CODE_NO Value,concat(CODE_NO,'-----',CODE_NAME) Text  from [dbo].[sys_code] where PARENT_NO=99");
            tables.Clear();

            foreach (var dr in dstable)
            {
                string Id = dr.Value.ToString();
                string Title = dr.Text.ToString().Trim();
                tables.Add(new SelectListItem { Value = Id, Text = Title });
            }

            return tables;
        }


                   
        internal List<SelectListItem> GetVU_SUITE()
        {
            List<SelectListItem> tables = new List<SelectListItem>();
            var dstable = vehicle_usageRepository.SqlWithParamsDynamic("select CODE_NO Value,concat(CODE_NO,'-----',CODE_NAME) Text  from [dbo].[sys_code] where PARENT_NO=99");
            tables.Clear();

            foreach (var dr in dstable)
            {
                string Id = dr.Value.ToString();
                string Title = dr.Text.ToString().Trim();
                tables.Add(new SelectListItem { Value = Id, Text = Title });
            }

            return tables;
        }


                   
        internal List<SelectListItem> GetVU_OPERATOR1()
        {
            List<SelectListItem> tables = new List<SelectListItem>();
            var dstable = vehicle_usageRepository.SqlWithParamsDynamic("select OPERATOR_ID Value,concat(OPERATOR_ID,'-----',OPERATOR_NAME) Text from [dbo].[vehicle_operator] where OPERATOR_ID Is not null and OPERATOR_NAME Is not null");
            tables.Clear();

            foreach (var dr in dstable)
            {
                string Id = dr.Value.ToString();
                string Title = dr.Text.ToString().Trim();
                tables.Add(new SelectListItem { Value = Id, Text = Title });
            }

            return tables;
        }


                   
        internal List<SelectListItem> GetVU_OPERATOR1_SMS_TYPE()
        {
            List<SelectListItem> tables = new List<SelectListItem>();
            var dstable = vehicle_usageRepository.SqlWithParamsDynamic("select CODE_NO Value,concat(CODE_NO,'-----',CODE_NAME) Text  from [dbo].[sys_code] where PARENT_NO=106");
            tables.Clear();

            foreach (var dr in dstable)
            {
                string Id = dr.Value.ToString();
                string Title = dr.Text.ToString().Trim();
                tables.Add(new SelectListItem { Value = Id, Text = Title });
            }

            return tables;
        }
    }
}